//白名单设置
let whitePages = [
    '/pages/login/login',
    '/pages/login/register',
    '/pages/login/register2',
    '/pages/login/forgetPwd',
    '/pages/login/editPwd',
    '/pages/user/protocol',
    '/pages/user/terms',
    '/pages/index/index',

]
let list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
list.forEach(item => {
    uni.addInterceptor(item, {
        invoke(e) {
            const token = uni.getStorageSync('TOKEN_KEY')
            const url = e.url.split('?')[0]
            if (whitePages.includes(url)) {
                return true
            } else if (token === '' || token === null || token === undefined) {
                uni.showToast({
                    title: '该页面需要登录才能访问，请先登录',
                    icon: 'none',
                })
                uni.navigateTo({
                    url: '/pages/login/login',
                })
                return true
            } else {
                return true
            }
        },
        fail(err) {
            console.log(err)
        },
    })
})